package com.jammingpro.blog_system.service;

import com.jammingpro.blog_system.mapper.BlogInfoMapper;
import com.jammingpro.blog_system.mapper.UserInfoMapper;
import com.jammingpro.blog_system.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;

    /**
     * 用户名密码正确性校验
     * @param userInfo 用户信息
     * @return 是否正确
     */
    public UserInfo getUserInfoByUserName(UserInfo userInfo) {
        UserInfo ret = userInfoMapper.getUserInfoByUserName(userInfo);
        return ret;
    }

    /**
     * 查询用户信息-通过id
     * @param id 用户id
     * @return 用户信息
     */
    public UserInfo getUserInfoById(Integer id) {
        return userInfoMapper.getUserInfoById(id);
    }

    /**
     * 获取文章作者信息
     * @param id 文章id
     * @return 文章作者信息
     */
    public UserInfo getAuthorInfo(Integer id) {
        Integer authorId = blogInfoMapper.getAuthorIdByBlogId(id);
        if(authorId == null) {
            return null;
        }
        return userInfoMapper.getUserInfoById(authorId);
    }
}
